var app = getApp()
var page = 1
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabindex: 0,
    zx_id:""
  },
  tabChose: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;

    that.setData({
      tabindex: index,
      zx_id:e.currentTarget.dataset.zx_id
    })
    that.getzixunlist();
  },

  btdetail:function(e){
    var id = e.currentTarget.dataset.id
    var p_id = e.currentTarget.dataset.p_id
    var zid = e.currentTarget.dataset.zid
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zixunanlixq/zixunanlixq?id=' + id + '&p_id=' + p_id + '&zid=' + zid,
    })
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this

    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    console.log(options.zixun);
    app.util.request({
      'url': "entry/wxapp/index.zixunfenlei",
      success: function (res) {
        console.log(res)
        if(options.zx_id=='undefined'){
          var zx_id = res.data[0].zx_id
        }else{
          var zx_id = options.zx_id
        }
        that.setData({
         tabList : res.data,
          zx_id: zx_id
        })
        if(options.zx_id){
          for(var i=0;i<res.data.length;i++){
            if(res.data[i].zx_id==options.zx_id){
              that.setData({
                tabindex:i+1
              })
            }
          }
        }
        that.getzixunlist();
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },

  getzixunlist:function(){
    var that = this;
    console.log(that.data.zx_id)
    app.util.request({
      'url': 'entry/wxapp/zixun.zixunyi',
      data: {
        zx_id: that.data.zx_id,
        tabindex:that.data.tabindex
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          zixun: res.data,
        })
      },
      fail: function (err) {
        console.log(err)
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})